/*
 * @Description: 
 * @Author: kangjie
 * @Date: 2021-12-28 18:16:58
 * @LastEditors: kangjie
 * @LastEditTime: 2021-12-28 19:47:48
 */
import Vue from 'vue'
import Vuex from 'vuex'
// 引入注册模块
import register from './register/register'
// 引入用户模块
import user from './user/user'
import category from './category/category'
import product from './product/product'
// 引入购物车模块
import shopcar from './shopcar/shopcar'
Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    // token存储
    token: localStorage.getItem('token') ? localStorage.getItem('token') : ''
  },
  mutations: {
    //存储token
    setToken(state, token) {
      state.token = token;
      localStorage.setItem("token", token.token);
    },
    //删除token
    delToken(state) {
      state.token = '';
      localStorage.removeItem("token");
    }
  },
  actions: {
  },
  modules: {
    // 注册模块
    register,
    // 用户模块
    user,
    category,
    product,
    // 购物车模块
    shopcar
  }
})
